package com.zhou.test.annotation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

// WorkOverTime 自定义注解验证类
public class WorkOverTimeValidator implements ConstraintValidator<WorkOverTime, Integer> {
    WorkOverTime work;
    int max;

    public void initialize(WorkOverTime work) {
        //获取注解的定义
        this.work = work;
        max = work.max();
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        // 建议逻辑
        if (value == null) {
            return true;
        }

        return value < max;
    }


}
